package net.e4net.watrix.action.join;

import java.io.IOException;





import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.e4net.watrix.ActionResponse;
import net.e4net.watrix.ResponseData;
import net.e4net.watrix.WatrixContext;
import net.e4net.watrix.WatrixException;
import net.e4net.watrix.base.member.MemberVO;
import net.e4net.watrix.common.hao.RequestParser;
import net.e4net.watrix.common.tao.TaoConnection;
import net.e4net.watrix.common.tao.TaoDataSet;
import net.e4net.watrix.common.tao.TaoResult;
import net.e4net.watrix.example.base.ExamConstants;
import net.e4net.watrix.runtime.AbstractAction;
import net.e4net.watrix.runtime.ActionException;


@SuppressWarnings("serial")
public class MemberJoinActn extends AbstractAction {

	
	@SuppressWarnings("unchecked")
	public ActionResponse execute(WatrixContext context, HttpServletRequest request,
			HttpServletResponse response) throws IOException, ServletException,
			WatrixException {
		
		RequestParser parser = context.getRequestParser("default", request, response);
		ResponseData data = super.getResponseData(request);
		TaoConnection con = null;
		TaoResult result = null;
		String responsekey = "default";
		
		
		MemberVO mdao = new MemberVO();
		mdao.setId( parser.getParameter("id") );
		mdao.setName( parser.getParameter("name") );
		mdao.setJumin1( parser.getParameter("jumin1") );
		mdao.setJumin2( parser.getParameter("jumin2") );
		mdao.setAddress( parser.getParameter("address") );
		mdao.setPasswd( parser.getParameter("passwd") );
		mdao.setDepartment( parser.getParameter("department") );
		mdao.setSex( parser.getParameter("sex") );
		mdao.setEmail( parser.getParameter("email") );
		mdao.setMessage( parser.getParameter("message") );
		
		mdao.setHp( parser.getParameter("hp1") + "-" + parser.getParameter("hp2") + "-"	+
				parser.getParameter("hp3"));
		
		mdao.setHomephone( parser.getParameter("homephone1") + "-" + parser.getParameter("homephone2") + "-" 
				+ parser.getParameter("homephone3") );
		
		try{
			con = context.getTaoConnection("default", null);
			TaoDataSet dataSet = TaoDataSet.getInstance();
			dataSet.setString("ID", mdao.getId());
			dataSet.setString("NAME",mdao.getName());
			dataSet.setString("JUMIN1", mdao.getJumin1());
			dataSet.setString("JUMIN2", mdao.getJumin2());
			dataSet.setString("HP", mdao.getHp());
			dataSet.setString("ADDRESS", mdao.getAddress());
			dataSet.setString("HOMEPHONE", mdao.getHomephone());
			dataSet.setString("PASSWD", mdao.getPasswd());
			dataSet.setString("DEPARTMENT", mdao.getDepartment());
			dataSet.setString("SEX", mdao.getSex());
			dataSet.setString("EMAIL", mdao.getEmail());
			dataSet.setString("MESSAGE",mdao.getMessage());
			
			
			result = con.execute("net.e4net.watrix.proc.join.MemberJoinProc",dataSet);
			if(result.getStatusCode() != 1){
				data.put("errorCode",result.getStatusString());
				responsekey = "error";
			}
		}catch(Throwable t){
			throw new ActionException(this.getActionDesc(context),
					context.getMessage(ExamConstants.SYSTEM_ERROR,null),t);
		}finally{
			try{con.close();}catch(Throwable ignore){}
		}
			
		return super.getActionResponse(context, responsekey);
	}
		
}
